<html>
<head><meta charset="utf-8"><title>rustfmt · edition 2021 · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/index.html">edition 2021</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html">rustfmt</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="220996757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/220996757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yerkebulan Tulibergenov <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#220996757">(Dec 27 2020 at 06:45)</a>:</h4>
<p>Hello. Do you think it would worthwhile to consider changing how rustfmt works in the new edition? There is a long thread in internals about rustfmt, but one of them stands out for me: <a href="https://internals.rust-lang.org/t/forced-rustfmt-is-a-roadblock-to-contributing/11913/9">https://internals.rust-lang.org/t/forced-rustfmt-is-a-roadblock-to-contributing/11913/9</a></p>



<a name="220996915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/220996915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yerkebulan Tulibergenov <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#220996915">(Dec 27 2020 at 06:49)</a>:</h4>
<p>Perhaps <span class="user-mention" data-user-id="198824">@Kornel</span>, <span class="user-mention" data-user-id="120791">@RalfJ</span>,  <span class="user-mention" data-user-id="222471">@BurntSushi</span>  might have an opinion about that, since they were active participants in that thread. Sorry for noise.</p>



<a name="221007823"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221007823" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221007823">(Dec 27 2020 at 12:55)</a>:</h4>
<p>I do have opinions on rustfmt, yeah (also see the issue tracker)... but in the end this is down to the people doing the work, all I can do is try to provide constructive feedback</p>



<a name="221028729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221028729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221028729">(Dec 27 2020 at 23:45)</a>:</h4>
<p><span class="user-mention" data-user-id="200172">@Yerkebulan Tulibergenov</span> There are a couple of independent questions here. First, whether we <em>want</em> to make that change. But second, <em>can</em> we make that change in a reasonable way? <code>cargo fmt</code> could get the edition from <code>Cargo.toml</code>, but does that imply that using <code>rustfmt</code> directly will require passing the edition?</p>



<a name="221028775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221028775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221028775">(Dec 27 2020 at 23:46)</a>:</h4>
<p>I don't think rustfmt currently has a mechanism for passing the edition; we'd have to add such a mechanism and allow it to change the defaults.</p>



<a name="221028780"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221028780" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221028780">(Dec 27 2020 at 23:46)</a>:</h4>
<p>Also, changing the rustfmt defaults would be rather disruptive to the ecosystem, in terms of churn.</p>



<a name="221028790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221028790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221028790">(Dec 27 2020 at 23:47)</a>:</h4>
<p>And disruptive in a second way: it'd create the expectation that rustfmt <em>can</em> change at an edition boundary, which would invite substantial bikeshedding on a regular cadence...</p>



<a name="221028916"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221028916" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221028916">(Dec 27 2020 at 23:50)</a>:</h4>
<p>(rustfmt does have a mechanism for passing the edition, either in config <a href="https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#edition">https://github.com/rust-lang/rustfmt/blob/master/Configurations.md#edition</a> or <code>--edition</code> on the CLI)</p>



<a name="221029164"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221029164" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221029164">(Dec 27 2020 at 23:57)</a>:</h4>
<p>I suspect that maintaining multiple very different formatting versions would be relatively painful, given that even one has tons of edge cases and "bugs" to consider</p>



<a name="221029217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221029217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221029217">(Dec 27 2020 at 23:58)</a>:</h4>
<p>I'm not sure that editions are the right mechanism for formatting anyway, and I know that there are discussions about a 2.0. we should talk to the rustfmt devs but I suspect we should not tie anything to the edition.</p>



<a name="221029292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221029292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221029292">(Dec 28 2020 at 00:00)</a>:</h4>
<p>that mechanism is most likely to specify the parsing side rather than the formatting result</p>



<a name="221065489"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221065489" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221065489">(Dec 28 2020 at 14:50)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/268952-edition/topic/rustfmt/near/221028780">said</a>:</p>
<blockquote>
<p>Also, changing the rustfmt defaults would be rather disruptive to the ecosystem, in terms of churn.</p>
</blockquote>
<p>well, the proposed change is to make rustfmt less "invasive" by staying closer to the original formatting of the code -- so there shouldn't be any churn for existing rustfmt-using projects</p>



<a name="221073597"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221073597" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221073597">(Dec 28 2020 at 16:48)</a>:</h4>
<p><span class="user-mention" data-user-id="116113">@lqd</span> Ah, that makes sense.</p>



<a name="221073674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221073674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221073674">(Dec 28 2020 at 16:50)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> That's the theory, but rustfmt is subtle and sometimes quick to anger, and that proposal would be a <em>major</em> change.</p>



<a name="221073695"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221073695" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221073695">(Dec 28 2020 at 16:50)</a>:</h4>
<p>Doing that with the added constraint of not changing any existing formatting would be an even bigger challenge.</p>



<a name="221073794"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221073794" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221073794">(Dec 28 2020 at 16:52)</a>:</h4>
<p>That's leaving aside whether people want the change. Some do, clearly. But we've also had reports from people who want to be able to utterly reformat code to normalize it without regard for the existing formatting. Which suggests that at the very least the current behavior is useful and still desirable in at least some circumstances.</p>



<a name="221257021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221257021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Kornel <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221257021">(Dec 30 2020 at 23:57)</a>:</h4>
<p>My deal-breaker issue with rustfmt is that it doesn't preserve author's decision on single-line vs multi-line formatting, like gofmt does. AFAIK rustfmt doesn't even have a setting for this. It'd be great if this was changed, but I worry that if it's not an existing option, there's no straightforward path for making this change for the next edition.</p>



<a name="221257224"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221257224" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221257224">(Dec 31 2020 at 00:01)</a>:</h4>
<p>+1 to not tying to an edition, but I also strongly dislike rustfmt for the reasons mentioned in <a href="https://users.rust-lang.org/t/what-do-you-think-about-gofmt-vs-rustfmt/51605">https://users.rust-lang.org/t/what-do-you-think-about-gofmt-vs-rustfmt/51605</a>: it's too invasive and leaves no room for the author's judgement without sprinkling <code>rustfmt::allow</code> everywhere. In particular I don't like that it will split expressions onto multiple lines when they get too large, or collapse them into a single line when they get 'small enough'. I would <em>love</em> an opt-in way to tell it not to do that (<code>use_min_heuristics = max</code> is sort of close, but still too invasive).</p>



<a name="221257282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221257282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221257282">(Dec 31 2020 at 00:02)</a>:</h4>
<p>or in other words I think something like <code>clang-format</code> would be great, where it only fixes the most glaring issues and leaves most of the rest up to the author's judgement</p>



<a name="221257360"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221257360" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221257360">(Dec 31 2020 at 00:04)</a>:</h4>
<p><span class="user-mention" data-user-id="198824">@Kornel</span> heh, it turns out you said the same thing but better <a href="https://users.rust-lang.org/t/what-do-you-think-about-gofmt-vs-rustfmt/51605/5?u=jyn514">https://users.rust-lang.org/t/what-do-you-think-about-gofmt-vs-rustfmt/51605/5?u=jyn514</a></p>



<a name="221273787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221273787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221273787">(Dec 31 2020 at 06:54)</a>:</h4>
<p>When writing messy branches that I want to cleanup afterwards and rebase after cherry-picking some commits to master, the normalizing behavious is very useful. I can use git filter-branch to format all commits and then when I rebase. I don't have to worry much about changed formatting due to the normalizing behaviour of rustfmt.</p>



<a name="221292556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221292556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221292556">(Dec 31 2020 at 14:15)</a>:</h4>
<p>So that's another distinction: I think the 'format everything for me' mode should be different from 'format the things that are clearly wrong', and that CI should only check the second</p>



<a name="221298860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221298860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221298860">(Dec 31 2020 at 16:07)</a>:</h4>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> That depends on whether you see the purpose of rustfmt in CI as "deal with major formatting issues" or "make formatting always uniform".</p>



<a name="221298912"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221298912" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221298912">(Dec 31 2020 at 16:08)</a>:</h4>
<p>I would personally prefer to make rustfmt smarter and keep the normalizing behavior.</p>



<a name="221305833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221305833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Chris Denton <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221305833">(Dec 31 2020 at 17:52)</a>:</h4>
<p>Can rustfmt be made smarter here? E.g. calculating some measure of line complexity for Rust code sounds like a hard research problem.</p>



<a name="221305862"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221305862" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221305862">(Dec 31 2020 at 17:53)</a>:</h4>
<p>If CI only checks for "the things that are clearly wrong", doing "format everything for me" wouldn't be useful for the workflow I mentioned, as it will also format unrelated code.</p>



<a name="221415089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221415089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221415089">(Jan 02 2021 at 20:04)</a>:</h4>
<p>IIRC rustfmt already calculates some measure of complexity when trying to decide to split lines or not</p>



<a name="221415388"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221415388" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221415388">(Jan 02 2021 at 20:12)</a>:</h4>
<p>I also recall that.</p>
<p>However, a flag to blanket disable line changes would be most welcomed. Fix all the spacing, adjust commas, move braces where they go, delete excess blank lines, etc etc, just <strong>don't</strong> add/remove any newlines <em>within</em> an expression.</p>
<p>I would expect this to be an easy flag to implement, though that's purely a guess.</p>



<a name="221415546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221415546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Dirkjan Ochtman <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221415546">(Jan 02 2021 at 20:16)</a>:</h4>
<p>I mean, it would not be able to enforce line length, for one thing (which to me is a rather important property)</p>



<a name="221420654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221420654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221420654">(Jan 02 2021 at 22:25)</a>:</h4>
<p>If you turn on the "stop messing with my frikkin newlines" flag you clearly don't care about precise line length limits.</p>



<a name="221420810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/268952-edition%202021/topic/rustfmt/near/221420810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/268952-edition-2021/topic/rustfmt.html#221420810">(Jan 02 2021 at 22:29)</a>:</h4>
<p>And if we wanted it to, it could still fail for lines that are longer than some threshold, just means it'd be up to the user to fix it.  (Without taking a position on whether it should.)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>